//排序
$(document).on("blur", '.j-ajax-input', function (e) {
    var that = $(this), _val = that.val();
    if (_val == '') return false;
    if (that.attr('data-value') == _val) return false;
    if (!that.attr('data-href')) {
        layer.msg('请设置data-href参数');
        return false;
    }
    $.post(that.attr('data-href'), {val:_val}, function(res) {
        if (res.code == 1) {
            that.attr('data-value', _val);
        }
        layer.msg(res.msg);
    });
});


//图片上传oss
layui.use(['form','layer','upload'], function(){
    $ = layui.jquery;
    var form = layui.form
        ,layer = layui.layer,
        upload = layui.upload;
    //普缩略图
    var uploadInst = upload.render({
        elem: '#goodsImage',
        url: "/admin/Upload/uploadFile",
        ext: 'jpg|png|gif',
        drag:false,

        before: function(obj){
            //预读本地文件示例，不支持ie8
            obj.preview(function(index, file, result){
                $('#demos').attr('src', result); //图片链接（base64）
            });
        },
        done: function(res){
            //如果上传失败
            if(res.code == 200 ){
                $('#upload-thumbs').append('<input type="hidden" name="thumbnail_img" value="'+ res.data.src+'">');
            }else {
                layer.msg(res.msg);
            }
            //上传成功
        },


    });
    //焦点图
    var uploadInsts = upload.render({
        elem: '#goodsImages',
        url: "/admin/Upload/uploadFile",
        ext: 'jpg|png|gif',
        multiple:true,
        number:8,
        drag:false,
        done: function(res){
            //如果上传失败
            if(res.code == 200 ){
                $('#demo').append('<span class="image-block"><input type="hidden" name="focus_img[]" value="'+ res.data.src +'"><span class="del_btn"><i class="layui-icon">&#x1006;<img width="100" height="100" src="'+ res.data.src +'" class="layui-upload-img"></i></span></span>');
            }else {
                layer.msg(res.msg);
            }
            //上传成功
        },

    });




    $('.images-block-container').on('click','.del_btn',function(){
        var index_image = $(this).parents('.image-block').remove();
    });





    var layertip = null;
    $(document).on('mouseenter','.thumb',function(){
        //console.log(event);
        var im = ('<img class="thumb-show" src="'+$(this).attr('thumb')+'" >');
        var link = $(this).attr('href');
        //layertip=layer.tips('<img style="" src='"/ >', this, { tips:[2,'#009688'] ,area: ['宽度', '高度'],time:false});
        layertip = layer.tips( im, this, {
            tips: [2,'#009688'],
            skin: 'demo_class',
            time: false,
        });
    });

    //隐藏缩略图
    $(document).on('mouseleave','.thumb', function() {
        layer.close(layertip);
    });
});